<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table id="role_dg"></table>
		
		<script type="text/javascript">
			$(function(){
				$('#role_dg').datagrid({
					url:'roles',
					method:"get",
					fitColumns:true,
					pagination:true,
					border:false,
					scrollbarSize: 0,
					fit: true,
					pageSize:10,
					columns:[[
						{field:'id',title:'id',width:20},
						{field:'roleName',title:'roleName',width:60},
						{field:"state",title:"state",width:55,formatter:function(value,row,index){
							if(value == 1){
								return "正常状态";
							}else{
								return "禁用状态";
							}
						}},
						{field:'permissions',title:'permissions',width:190,formatter:function(value,row,index){
							var permissionsStr = "";
							if(value!=null && value.length>0){
								for(var i=0;i<value.length;i++){
									 permissionsStr += "【"+ value[i].resource +"】"
								}
							}
							return  permissionsStr;
						}}
					]]
				});
		
			})
			function add(){
				alert("未定义");
			}
			function deleted(){
				alert("未定义");
			}
			function put(){
				var rows = $("#role_dg").datagrid("getSelections");
				
				if(rows.length == 0){
					$.messager.alert("信息提示","请勾选您要修改的数据！","info");
				}else{
					$.messager.confirm("信息提示", "确定要改变选中的角色状态吗？", function(result) {
						if (result) {
							var ids = [];
							$(rows).each(function() {
								ids.push(this.id);
							});
							$.ajax({
								url: "/filesharingsystem/roles",
								method: "put",
								contentType: "application/json;charset=utf-8",
								data: JSON.stringify(ids),
								success: function(data) { //"ok","error"
									if (data == "ok") {
										role_reload();
									} else {
										$.messager.alert("信息提示", "修改失败！", "info");
									}
								}
							});
						}
					});				
				}
			}
			function select(){
				alert("未定义");
			}
			function role_reload() {
				$("#role_dg").datagrid("reload");
			}
		</script>
	</body>
</html>
